package com.eliza.music.view.music.recommend

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Menu
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.eliza.music.compoment.music.CategoryView
import com.eliza.music.compoment.music.SongView
import com.eliza.music.model.vm.VmRecommend
import com.eliza.music.view.music.settinng.SettingX
import kotlinx.coroutines.launch

@Preview
@Composable
private fun SettingPreview() {
    Recommend.Route()
}

object Recommend {
    @Composable
    fun Route(modifier: Modifier = Modifier) {
        Screen(vm = hiltViewModel())
    }

    @Composable
    fun Screen(vm: VmRecommend) {
        val scope = rememberCoroutineScope()
        SettingX.Index() { drawerState, modi ->
            Column(
                modifier = Modifier
                    .padding(2.dp)
                    .background(Color(245, 245, 245))
            ) {
                IconButton(onClick = {
                    scope.launch {
                        drawerState.open()
                    }
                }) {
                    Icon(imageVector = Icons.Rounded.Menu, contentDescription = "")
                }
                val collectAsState = vm.categoryList.collectAsState()
                collectAsState.value.forEach { item ->
                    when (item.type) {
                        1 -> CategoryView.ItemList(
                            data = item
                        )
                        2 -> item.children.forEach {
                            SongView.ItemInList(it)
                        }
                    }

                }

            }
        }
    }
}

